package com.denlaku.longan.service.impl;

import com.denlaku.longan.anno.RequiredTx;
import com.denlaku.longan.repository.ConditionRepository;
import com.denlaku.longan.service.ConditionService;
import com.denlaku.longan.util.SnowflakeUtils;
import com.denlaku.longan.vo.Condition;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tianx
 */
@Service
public class ConditionServiceImpl implements ConditionService {
    @Autowired
    private ConditionRepository conditionRepository;

    @Override
    @RequiredTx
    public void batchAdd(List<Condition> conditionList) {
        if (CollectionUtils.isNotEmpty(conditionList)) {
            conditionList.forEach(filter -> filter.setId(SnowflakeUtils.nextId()));
            conditionRepository.batchAdd(conditionList);
        }
    }

    @Override
    @RequiredTx
    public void delete(Long tenantId, List<Long> componentIds) {
        conditionRepository.delete(tenantId, componentIds);
    }

    @Override
    public List<Condition> list(Long tenantId, List<Long> componentIds) {
        return conditionRepository.list(tenantId, componentIds);
    }

}
